import { useRoutes } from "react-router-dom"
import RouterEnter from "./RouterEnter"
import LoginView from "../views/login/LoginView"
import NotFound from "../views/404/NotFound"
import LayoutView from "../views/layout/LayoutView"
import RouterMap from "./RouterMap"
import { useSelector } from "react-redux"
import type { UserStore } from "../type/StoreType"

function RouterView () {

  // #region 变量声明
  const { user } = useSelector((state: { user: UserStore }) => state.user)
  // console.log(RouterMap.filter(v => user.routers.includes(v.path as string)))
  // #endregion

  // #region 函数

  // #endregion

  // #region Hooks

  // #endregion

  return useRoutes([
    {
      path: '/',
      element: <RouterEnter element={ <LayoutView /> } />,
      children: user.routers ? RouterMap.filter(v => user.routers.includes(v.path as string)) : []
    },
    {
      path: '/login',
      element: <LoginView />
    },
    {
      path: '*',
      element: <RouterEnter element ={ <NotFound /> } />
    }
  ])
}

export default RouterView
